package com.youuvs.feign;

import com.youuvs.domain.Store;
import com.youuvs.jsonResult.JsonResult;
import feign.hystrix.FallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.*;

@FeignClient(name = "store-service",fallbackFactory = StoreFeignFallbackFactory.class)
@RequestMapping("/store")
@Repository
public interface StoreFeign {

    @GetMapping("/getById/{id}")
    Store select(@PathVariable("id") Long id);

    @PostMapping("/insert")
    JsonResult insert(@RequestBody Store store);
}

@Component
class StoreFeignFallbackFactory implements FallbackFactory<StoreFeign>{

    @Override
    public StoreFeign create(Throwable throwable) {
        return new StoreFeign() {
            @Override
            public Store select(Long id) {
                return new Store(-1L,-1L,-998);
            }

            @Override
            public JsonResult insert(Store store) {

                return new JsonResult().setMsg("添加失败ProToSto");
            }
        };
    }
}
